<template>
  <view class="welcome" v-if='!!welcomeSrc' @touchmove.stop.prevent catchtouchmove="true">
    <view class='wel-container'>
      <image @load="loadSuccess" @click="skipAdv" :src="welcomeSrc" class="kaiping" mode="widthFix" lazy-load="true">
      </image>
      <view class="close-content" v-if='showClose' @click="closeWelcome('clickClose')">
        <view class="click-area">
          <image lazy-load="true" src="https://100000063-1252208446.file.myqcloud.com/images/20221220-132544.png"
            mode="widthFix">
          </image>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import util from '@/utils/util.js';
  import cmsMethods from '@/utils/cmsItems.js';
  export default {
    data() {
      return {
        showClose: false,
        welcomeSrc: '',
        shareTitle: '',
        hasRequest: false,
      }
    },
    computed: {
      ishasRequest() {
        return !!this.welcomeSrc
      },
    },
    async mounted() {
      await this.$onLaunched;
      let notTrack = !this.welcomeSrc
      this.getAdvInfo()
    },
    methods: {
      getAdvInfo() {
        let that = this
        cmsMethods.getCMSPageInfo('cms/Adv1').then(
          async res => {
            let advInfo = res
            if (res && res.shareImage) {
              this.welcomeSrc = res.shareImage
              this.shareTitle = res.shareTitle
              if(!this.ishasRequest) {
                that.$commonSensors.popupEvent('PopupExposure', {'popup_type' : '宣传', 'popup_name': '首页开屏弹窗'})
              }
            }
          })
      },
      loadSuccess() {
        this.success = true
        setTimeout(() => {
          this.showClose = true
        })
      },
      closeWelcome(type) {
        this.$store.commit('changeTstabbar', false)
        this.$emit('closeWelcome')
		getApp().globalData.event.emit('swiperAutoPlay')
        if(!!type) {
          this.$commonSensors.popupEvent('PopupClick', {'popup_type' : '宣传', 'popup_name': '首页开屏弹窗', 'button_name': '关闭'})
        }
      },
      skipAdv() {
        let trackInfo = this.shareTitle
        let trackParams = util.urlToObj(trackInfo)
        let {
          eventName,
          advSkipPath
        } = trackParams
        uni.navigateTo({
          url: advSkipPath
        })
        let trackJson = trackParams
        delete trackJson.eventName
        delete trackJson.advSkipPath
        getApp().commonClTrack(eventName, trackJson);
        this.closeWelcome()
        this.$commonSensors.popupEvent('PopupClick', {'popup_type' : '宣传', 'popup_name': '首页开屏弹窗', 'button_name': '即刻购买'})
      }
    }
  }
</script>

<style lang="scss">
  .welcome {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(0, 0, 0, 0.8);
    transform: scaleY(2px);
    z-index: 1500;

    &.trans {
      background: rgba(0, 0, 0, 0)
    }

    .wel-container {
      position: relative;
      top: 50%;
      transform: translateY(-50%);
      padding-top: -74rpx;

      &.display-none {
        transition: all 1s;
        top: 65%;
        opacity: 0;
      }

      .kaiping {
        width: 552rpx;
        margin: 0 auto;
        height: 789rpx;
      }

      .close-content {
        position: absolute;
        width: 60rpx;
        height: 60rpx;
        bottom: -94rpx;
        left: 50%;
        transform: translate(-50%, -50%);
        display: flex;
        align-items: center;
        justify-content: center;

        image {
          width: 32rpx;
        }
      }
    }
  }
</style>
